package com.codeduck.config;

import com.codeduck.constant.KafkaConst;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.TopicBuilder;

/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @date: 2023/2/27
 */
@Configuration
public class TopicRegister {

    /**
     * NewTopic: 当topic存在时，则跳过创建
     */
    @Bean
    public NewTopic simpleTopic() {
        return TopicBuilder
                .name(KafkaConst.SIMPLE_TOPIC)
                .partitions(3)
                .replicas(1)
                .build();
    }

    @Bean
    public NewTopic javaTopic() {
        return TopicBuilder
                .name(KafkaConst.JAVA_TOPIC)
                .partitions(3)
                .replicas(1)
                .build();
    }
}
